package com.jozen.smart_toilet_system.adapter;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jozen.smart_toilet_system.R;
import com.jozen.smart_toilet_system.bean.ConAllowanceModel;
import com.ruffian.library.widget.REditText;

public class ConAllowanceAdapter extends BaseQuickAdapter<ConAllowanceModel, BaseViewHolder> {

    public ConAllowanceAdapter() {
        super(R.layout.setting_con_allowance_list_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, ConAllowanceModel item) {
        TextView tv_title = helper.getView(R.id.tv_title);
        REditText et_sn_code = helper.getView(R.id.et_sn_code);


        if (!TextUtils.isEmpty(item.getTitle())) {
            tv_title.setText(item.getTitle());
        }

        if (!TextUtils.isEmpty(item.getSnNo())) {
            et_sn_code.setText(item.getSnNo());
        }else {
            et_sn_code.setText("");
        }

        et_sn_code.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!TextUtils.isEmpty(s.toString().trim())) {
                    getData().get(helper.getAdapterPosition()).setSnNo(s.toString().trim());
                } else {
                    getData().get(helper.getAdapterPosition()).setSnNo("");
                }
            }
        });
    }
}
